package day03;

import java.util.Scanner;

/**
 * 简易计算器，支持整数的加减乘除，包括一个友好的用户提示
 * 要求：加减乘除以方法形式，在主函数中调用
 * Created by Shinelon on 2016/9/11.
 */
public class HomeWork {

    public static void main(String[] args) {
        while (true) {
            System.out.println("欢迎使用计算器！\n1.加法  2.减法  3.乘法  4.除法  5.退出");
            HomeWork work = new HomeWork();
            Scanner scan = new Scanner(System.in);
            int read = scan.nextInt();
            int x;
            int y;
            switch (read) {
                case 1:
                    System.out.println("请输入两个加数：");
                    x = scan.nextInt();
                    y = scan.nextInt();
                    System.out.println("加法结果是：" + work.add(x, y));
                    break;
                case 2:
                    System.out.println("请先输入减数再输入被减数：");
                    x = scan.nextInt();
                    y = scan.nextInt();
                    System.out.println("减法结果是：" + work.jf(x, y));
                    break;
                case 3:
                    System.out.println("请输入两个乘数：");
                    x = scan.nextInt();
                    y = scan.nextInt();
                    System.out.println("乘法结果是：" + work.cf(x, y));
                    break;
                case 4:
                    System.out.println("请先输入除数再输入被除数：");
                    x = scan.nextInt();
                    y = scan.nextInt();
                    if (y == 0)
                        System.out.println("无法计算");
                    else
                        System.out.println("除法结果是:" + work.df(x, y));
                case 5:
                    System.out.println("欢迎再次使用");
            }
            if (read==5)
            break;
        }
//        if (read == 1){//加法
//            System.out.println("请输入两个加数：");
//            int x = scan.nextInt();
//            int y = scan.nextInt();
//            System.out.println("加法结果是：" + work.add(x, y));
//        }
//        if (read==2){
//            System.out.println("请先输入减数再输入被减数：");
//            int x = scan.nextInt();
//            int y = scan.nextInt();
//            System.out.println("减法结果是：" + work.jf(x,y));
//        }
//        if (read==3){
//            System.out.println("请输入两个乘数：");
//            int x = scan.nextInt();
//            int y = scan.nextInt();
//            System.out.println("乘法结果是："+ work.cf(x,y));
//        }
//        if (read==4){
//            System.out.println("请先输入除数再输入被除数：");
//            int x = scan.nextInt();
//            int y = scan.nextInt();
//            if (y==0)
//                System.out.println("无法计算");
//            else
//                System.out.println("除法结果是："+ work.df(x,y));
//        }
        }


    public int add(int a, int b) {
        return a + b;
    }


    public int jf(int a, int b) {
        return a - b;
    }

    public int cf(int a, int b) {
        return a * b;
    }

    public int df(int a, int b) {
        return a / b;
    }
}
